/* $Id: ActionsUnitTest.java 63 2010-02-14 13:52:34Z aaron.day $ */
package org.crazydays.gameplan.controller;


import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.action.ExitApplication;
import org.crazydays.gameplan.action.OpenAboutDialog;
import org.crazydays.gameplan.controller.ActionController;
import org.crazydays.gameplan.db.Database;
import org.crazydays.gameplan.db.action.CloseDatabase;
import org.crazydays.gameplan.db.action.CreateDatabase;
import org.crazydays.gameplan.db.action.OpenDatabase;
import org.crazydays.gameplan.db.action.SaveDatabase;
import org.crazydays.gameplan.db.action.SaveDatabaseAs;
import org.crazydays.gameplan.map.action.CreateMapDialog;
import org.crazydays.gameplan.map.action.ToggleGrid;
import org.crazydays.gameplan.model.Model;

/**
 * ActionsUnitTest
 */
public class ActionsUnitTest
{
    /**
     * Test initialize().
     */
    @Test
    public void testInitialize()
    {
        // objects
        CreateDatabase createDatabase = new CreateDatabase();
        OpenDatabase openDatabase = new OpenDatabase();
        CloseDatabase closeDatabase = new CloseDatabase();
        SaveDatabase saveDatabase = new SaveDatabase();
        SaveDatabaseAs saveDatabaseAs = new SaveDatabaseAs();
        CreateMapDialog createMapDialog = new CreateMapDialog();
        ToggleGrid toggleGrid = new ToggleGrid();
        OpenAboutDialog openAboutDialog = new OpenAboutDialog();
        ExitApplication exitApplication = new ExitApplication();

        // mocks
        Model model = createMock(Model.class);

        // setup
        ActionController actionController = new ActionController();
        actionController.setModel(model);
        actionController.setCreateDatabase(createDatabase);
        actionController.setOpenDatabase(openDatabase);
        actionController.setCloseDatabase(closeDatabase);
        actionController.setSaveDatabase(saveDatabase);
        actionController.setSaveDatabaseAs(saveDatabaseAs);
        actionController.setCreateMapDialog(createMapDialog);
        actionController.setToggleGrid(toggleGrid);
        actionController.setOpenAboutDialog(openAboutDialog);
        actionController.setExitApplication(exitApplication);

        // expect
        model.addDatabaseObserver(actionController);

        // replay
        replay(model);

        // test
        actionController.initialize();

        // verify
        verify(model);

        assertEquals("createDatabase", true, createDatabase.isEnabled());
        assertEquals("openDatabase", true, openDatabase.isEnabled());
        assertEquals("closeDatabase", false, closeDatabase.isEnabled());
        assertEquals("saveDatabase", false, saveDatabase.isEnabled());
        assertEquals("saveDatabaseAs", false, saveDatabaseAs.isEnabled());
        assertEquals("createMapDialog", false, createMapDialog.isEnabled());
        assertEquals("toggleGrid", false, toggleGrid.isEnabled());
        assertEquals("openAboutDialog", true, openAboutDialog.isEnabled());
        assertEquals("exitApplication", true, exitApplication.isEnabled());
    }

    /**
     * Test opened(Database).
     */
    @Test
    public void testOpened()
    {
        // objects
        Database database = new Database();
        CreateDatabase createDatabase = new CreateDatabase();
        OpenDatabase openDatabase = new OpenDatabase();
        SaveDatabase saveDatabase = new SaveDatabase();
        SaveDatabaseAs saveDatabaseAs = new SaveDatabaseAs();
        CloseDatabase closeDatabase = new CloseDatabase();
        CreateMapDialog createMapDialog = new CreateMapDialog();

        // setup
        ActionController actionController = new ActionController();
        actionController.setCreateDatabase(createDatabase);
        actionController.setOpenDatabase(openDatabase);
        actionController.setSaveDatabase(saveDatabase);
        actionController.setSaveDatabaseAs(saveDatabaseAs);
        actionController.setCloseDatabase(closeDatabase);
        actionController.setCreateMapDialog(createMapDialog);

        // test
        actionController.opened(database);

        assertEquals("createDatabase", false, createDatabase.isEnabled());
        assertEquals("openDatabase", false, openDatabase.isEnabled());
        assertEquals("saveDatabase", true, saveDatabase.isEnabled());
        assertEquals("saveDatabaseAs", true, saveDatabaseAs.isEnabled());
        assertEquals("createMapDialog", true, createMapDialog.isEnabled());
        assertEquals("closeDatabase", true, closeDatabase.isEnabled());
    }

    /**
     * Test closed(Database).
     */
    @Test
    public void testClosed()
    {
        // objects
        Database database = new Database();
        CreateDatabase createDatabase = new CreateDatabase();
        OpenDatabase openDatabase = new OpenDatabase();
        SaveDatabase saveDatabase = new SaveDatabase();
        SaveDatabaseAs saveDatabaseAs = new SaveDatabaseAs();
        CloseDatabase closeDatabase = new CloseDatabase();
        CreateMapDialog createMapDialog = new CreateMapDialog();

        // setup
        ActionController actionController = new ActionController();
        actionController.setCreateDatabase(createDatabase);
        actionController.setOpenDatabase(openDatabase);
        actionController.setSaveDatabase(saveDatabase);
        actionController.setSaveDatabaseAs(saveDatabaseAs);
        actionController.setCloseDatabase(closeDatabase);
        actionController.setCreateMapDialog(createMapDialog);

        // test
        actionController.closed(database);

        assertEquals("createDatabase", true, createDatabase.isEnabled());
        assertEquals("openDatabase", true, openDatabase.isEnabled());
        assertEquals("saveDatabase", false, saveDatabase.isEnabled());
        assertEquals("saveDatabaseAs", false, saveDatabaseAs.isEnabled());
        assertEquals("createMapDialog", false, createMapDialog.isEnabled());
        assertEquals("closeDatabase", false, closeDatabase.isEnabled());
    }

    /**
     * Test enableMapOptions().
     */
    @Test
    public void testEnableMapOptions()
    {
        // objects
        ToggleGrid toggleGrid = new ToggleGrid();

        // setup
        ActionController actionController = new ActionController();
        actionController.setToggleGrid(toggleGrid);

        // test
        actionController.enableMapOptions();

        // verify
        assertEquals("gridToggle", true, toggleGrid.isEnabled());
    }

    /**
     * Test disableMapOptions().
     */
    @Test
    public void testDisableMapOptions()
    {
        // objects
        ToggleGrid toggleGrid = new ToggleGrid();

        // setup
        ActionController actionController = new ActionController();
        actionController.setToggleGrid(toggleGrid);

        // test
        actionController.disableMapOptions();

        // verify

        assertEquals("gridToggle", false, toggleGrid.isEnabled());
    }
}
